/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class PrestacionDAOImpl implements orm.dao.PrestacionDAO {
	public Prestacion loadPrestacionByORMID(int pr_id_prestacion) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return loadPrestacionByORMID(session, pr_id_prestacion);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion getPrestacionByORMID(int pr_id_prestacion) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return getPrestacionByORMID(session, pr_id_prestacion);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion loadPrestacionByORMID(int pr_id_prestacion, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return loadPrestacionByORMID(session, pr_id_prestacion, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion getPrestacionByORMID(int pr_id_prestacion, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return getPrestacionByORMID(session, pr_id_prestacion, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion loadPrestacionByORMID(PersistentSession session, int pr_id_prestacion) throws PersistentException {
		try {
			return (Prestacion) session.load(orm.Prestacion.class, new Integer(pr_id_prestacion));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion getPrestacionByORMID(PersistentSession session, int pr_id_prestacion) throws PersistentException {
		try {
			return (Prestacion) session.get(orm.Prestacion.class, new Integer(pr_id_prestacion));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion loadPrestacionByORMID(PersistentSession session, int pr_id_prestacion, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Prestacion) session.load(orm.Prestacion.class, new Integer(pr_id_prestacion), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion getPrestacionByORMID(PersistentSession session, int pr_id_prestacion, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Prestacion) session.get(orm.Prestacion.class, new Integer(pr_id_prestacion), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion[] listPrestacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return listPrestacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion[] listPrestacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return listPrestacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion[] listPrestacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Prestacion as Prestacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Prestacion[]) list.toArray(new Prestacion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion[] listPrestacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Prestacion as Prestacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Prestacion[]) list.toArray(new Prestacion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion loadPrestacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return loadPrestacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion loadPrestacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return loadPrestacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion loadPrestacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Prestacion[] prestacions = listPrestacionByQuery(session, condition, orderBy);
		if (prestacions != null && prestacions.length > 0)
			return prestacions[0];
		else
			return null;
	}
	
	public Prestacion loadPrestacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Prestacion[] prestacions = listPrestacionByQuery(session, condition, orderBy, lockMode);
		if (prestacions != null && prestacions.length > 0)
			return prestacions[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePrestacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return iteratePrestacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePrestacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.PrestacionesPersistentManager.instance().getSession();
			return iteratePrestacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePrestacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Prestacion as Prestacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePrestacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Prestacion as Prestacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Prestacion createPrestacion() {
		return new orm.Prestacion();
	}
	
	public boolean save(orm.Prestacion prestacion) throws PersistentException {
		try {
			orm.PrestacionesPersistentManager.instance().saveObject(prestacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Prestacion prestacion) throws PersistentException {
		try {
			orm.PrestacionesPersistentManager.instance().deleteObject(prestacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Prestacion prestacion)throws PersistentException {
		try {
			if(prestacion.getPacientepa_id_paciente() != null) {
				prestacion.getPacientepa_id_paciente().prestacion.remove(prestacion);
			}
			
			if(prestacion.getTipo_prestaciontp_id_tipo_prestacion() != null) {
				prestacion.getTipo_prestaciontp_id_tipo_prestacion().prestacion.remove(prestacion);
			}
			
			return delete(prestacion);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Prestacion prestacion, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(prestacion.getPacientepa_id_paciente() != null) {
				prestacion.getPacientepa_id_paciente().prestacion.remove(prestacion);
			}
			
			if(prestacion.getTipo_prestaciontp_id_tipo_prestacion() != null) {
				prestacion.getTipo_prestaciontp_id_tipo_prestacion().prestacion.remove(prestacion);
			}
			
			try {
				session.delete(prestacion);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Prestacion prestacion) throws PersistentException {
		try {
			orm.PrestacionesPersistentManager.instance().getSession().refresh(prestacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Prestacion prestacion) throws PersistentException {
		try {
			orm.PrestacionesPersistentManager.instance().getSession().evict(prestacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
}
